/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fbv.tcc.classes;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.joda.time.DateTime;

/**
 *
 * @author Casa
 */
public class PontoRadiacao {

    private DateTime timeStamp;
    private double radiacao;

    /*
     * CONSTRUCTORS
     */
    public PontoRadiacao(DateTime timeStamp, double radiacao) {
        this.timeStamp = timeStamp;
        this.radiacao = radiacao;
    }

    public PontoRadiacao(String timeStamp, double radiacao) throws ParseException {

        Date data = new SimpleDateFormat("MM/dd/yy HH:mm").parse(timeStamp);
        String dataPadrao = new SimpleDateFormat("dd/MM/yyyy HH:mm").format(data);

        int ano = Integer.parseInt(dataPadrao.substring(6, 10));
        int mes = Integer.parseInt(dataPadrao.substring(3, 5));
        int dia = Integer.parseInt(dataPadrao.substring(0, 2));
        int hora = Integer.parseInt(dataPadrao.substring(11, 13).trim());
        int minuto = Integer.parseInt(dataPadrao.substring(14).trim());

        this.timeStamp = new DateTime(ano, mes, dia, hora, minuto);
        this.radiacao = radiacao;
    }

    public PontoRadiacao() {
    }

    //public PontoRadiacao(String data,)
    /*
     * GETTERS AND SETTERS
     */
    public DateTime getTimeStamp() {
        return timeStamp;
    }

    public void setTimeStamp(DateTime dataHora) {
        this.timeStamp = dataHora;
    }

    public void setTimeStamp(String data) {
        int ano = Integer.parseInt(data.substring(6, 10));
        int mes = Integer.parseInt(data.substring(3, 5));
        int dia = Integer.parseInt(data.substring(0, 2));
        int hora = Integer.parseInt(data.substring(12, 14).trim());
        int minuto = Integer.parseInt(data.substring(15, 17).trim());
        this.timeStamp = new DateTime(ano, mes, dia, hora, minuto);
    }

    public double getRadiacao() {
        return radiacao;
    }

    public void setRadiacao(double radiacao) {
        this.radiacao = radiacao;
    }

    public double toHour() {
       double minutos = timeStamp.getMinuteOfHour();
        double result = timeStamp.getHourOfDay()+minutos/60;        
        
        return result;
    }

    public int toMinutes() {
        int minutos = timeStamp.getMinuteOfDay();
        return minutos;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 61 * hash + (this.timeStamp != null ? this.timeStamp.hashCode() : 0);
        hash = 61 * hash + (int) (Double.doubleToLongBits(this.radiacao) ^ (Double.doubleToLongBits(this.radiacao) >>> 32));
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PontoRadiacao other = (PontoRadiacao) obj;
        if (this.timeStamp != other.timeStamp && (this.timeStamp == null || !this.timeStamp.equals(other.timeStamp))) {
            return false;
        }
        if (Double.doubleToLongBits(this.radiacao) != Double.doubleToLongBits(other.radiacao)) {
            return false;
        }
        return true;
    }
}
